import { reqGetTradeInfoData, reqGetUserAddressList } from "@/api"

const state = {
  tradeInfo: {},
  userAddressList:[]
}
const actions = {
  // 1. 获取要付款的商品列表
  async getTradeInfoData({commit}) {
    const result = await reqGetTradeInfoData()
    if (result.code === 200) {
      commit('SAVE_TRADE_INFO_DATA',result.data)
    } else {
      this.$message.error(result.message)
    }
  },
  // 2. 获取用户地址
  async getUserAddressList() {
    const result = await reqGetUserAddressList()
    console.log('address',result);
  }
}
const mutations = {
  SAVE_TRADE_INFO_DATA(state,tradeInfo) {
    state.tradeInfo = tradeInfo
  }
}
const getters = {
  // 1. 商品列表
  detailArrayList(state) {
    return state.tradeInfo.detailArrayList
  },
  // 2. 商品总金额
  originalTotalAmount(state) {
    return state.tradeInfo.originalTotalAmount
  },
  // 3. 折扣后的金额或是优惠后的金额
  totalAmount(state) {
    return state.tradeInfo.totalAmount
  },
  // 4. 商品件数
  totalNum(state) {
    return  state.tradeInfo.totalNum
  },
  // 5. 订单编号
  tradeNo(state) {
    return state.tradeInfo.tradeNo
  },
  // 6. 优惠金额或是折扣金额 或是返现金额
  activityReduceAmount(state) {
    return state.tradeInfo.activityReduceAmount
  }
}
export default {
  namespaced:true,
  state,
  actions,
  mutations,
  getters
}